// 巡查作业内容
import store from '../index'
import useConfirm from '@/hooks/useConfirm'
import { InspectionOperatModel } from '@/models'
const inspectionOperatModel = new InspectionOperatModel()

const getDefaultState = () => {
    return {
        info: {}
    }
}

const state = getDefaultState()

const getters = {}

const mutations = {
    setInfo(state, info) {
        state.info = info
    }
}

const actions = {
    async saveOrUpdate({ commit }, data) {
        const res = await useConfirm({
            text: '是否确定保存表单',
            model: inspectionOperatModel,
            modelAction: 'saveOrUpdate',
            data
        })
        return res
    },
    async delete({ commit }, data) {
        const res = await useConfirm({
            text: '是否确定删除表单',
            model: inspectionOperatModel,
            modelAction: 'delete',
            data
        })
        return res
    },
    async detail({ commit }, { id, edit = true }) {
        try {
            store.commit('openLoading')
            // 传filter参数代表会自动出来后端无数据的字段为-
            const res = await inspectionOperatModel.detail({ id }, edit ? null : 'filter')
            console.log('res :>> ', res)
            commit('setInfo', res)
            return res
        } finally {
            store.commit('closeLoading')
        }
    }
}

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}
